package com.liuluo.homework1025hou.Controller

import com.liuluo.homework1025hou.domain.Student
import com.liuluo.homework1025hou.service.StudentService
import com.liuluo.homework1025hou.service.StudentServiceJava
import org.springframework.web.bind.annotation.*

@RestController
@CrossOrigin("*")
@RequestMapping("/student")
class StudentController(private val studentService: StudentService,
                        private val studentServiceJava: StudentServiceJava
) {
//添加一个学生信息
    @PostMapping("/list")
    fun addStudent(@RequestBody student: Student):Boolean {
        return studentService.add(student)>0
    }
//获取列表全部内容
    @GetMapping("/all")
    fun getAll(): List<Student>{
        return studentService.getAll()
    }
//删除学生信息通过id
    @DeleteMapping("/{id}")
    fun delete(@PathVariable id:Int):Boolean{
        return studentService.delete(id)>0
    }
//修改学生信息通过id
    @PutMapping("/update")
    fun update(@RequestBody student: Student):Boolean{
        return studentService.update(student)>0
    }
//查询学生信息通过id
    @GetMapping("/{id}")
    fun getById(@PathVariable id:Int): List<Student>{
        return studentService.getOneById(id)
    }
//查询学生信息通过姓名
    @PostMapping("/{name}")
    fun addStudent(@PathVariable name: String): List<Student>{
        return studentService.getOneByName(name)
    }
//多条件查询姓名或id
    @GetMapping("/ByConditionOr")
    fun selectByCondition(@RequestParam(required = false) name: String,
                          @RequestParam(required = false) id: Int): List<Student>{
        return studentService.selectByCondition(id,name)
    }
//查询通过性别
    @GetMapping("/byGender/{gender}")
    fun selectByGender(@PathVariable(required = false) gender: String): List<Student>{
        return studentServiceJava.getByGender(gender)
    }
//出生日期区间查询
    @GetMapping("/betweenBirthday")
    fun selectByBirthday(@RequestParam(required = false) birthdayStart: String,@RequestParam(required = false) birthdayEnd: String): List<Student>{
        return studentServiceJava.getBetweenBirthday(birthdayStart,birthdayEnd)
    }
//姓名模糊搜索
    @GetMapping("/like/{name}")
    fun selectLikeName(@PathVariable name: String):List<Student>{
        return studentServiceJava.getLikeName(name)
    }
}